<?php
/**
 * User: zoudingyong <sheyingtg@qq.com>
 * Date: 2018/11/5
 */

namespace classes;

use think\Db;

class Order
{

    public static $order = 'jixie_order';

    /**
     * 支付业务处理
     * @param $order
     * @param $out_trade_no
     * @param $total_money
     * @param string $pay_type
     * @param string $transaction_id
     * @return bool
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function PayByMoneyCommon($order, $out_trade_no, $total_money, $pay_type = '1', $transaction_id = '')
    {

        if (!$order || !$out_trade_no || $total_money <= 0) return false;
        if ($order['pay_status'] == 0) {

            DB::name(self::$order)->where('order_id', $order['order_id'])->update(
                [
                    'order_no' => $out_trade_no,
                    'pay_status' => 1,
                    'pay_price' => $total_money,
                    'transaction_id' => $transaction_id,
                    'pay_type' => $pay_type,//支付方式 1微信支付
                    'pay_time' => date('Y-m-d H:i:s', time())
                ]);
            $order = Db::name(self::$order)->where('order_id', $order['order_id'])->find();
            if ($order['pay_status'] == 1) {

                //共用逻辑处理
                Goods::Buy($order);
            }
            return true;
        }
        return false;
    }


}